package com.wondersgroup.fjzlpt.org.dao.impl.jgqy.lshgl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.quick.framework.boot.repository.sql.bean.SQLBean;
import com.quick.framework.boot.repository.sql.bean.page.PageQuerySQLBean;
import com.quick.framework.boot.repository.sql.bean.table.TableBean;
import com.quick.framework.boot.repository.sql.jdbcTemplate.impl.BaseJTDAOImpl;
import com.quick.framework.boot.repository.sql.jdbcTemplate.rs.ResultHandlerConstant;
import com.wondersgroup.fjzlpt.org.dao.inter.jgqy.lshgl.LshglDAO;
@Repository
public class LshglDAOImpl extends BaseJTDAOImpl implements LshglDAO{
	@Override
	@Autowired
	@Qualifier("TB_JGQY_LSHGL")
	public void setTb(TableBean tb) {
		super.setTb(tb);
	}

	/**
	 * 分页查询
	 */
	public JSONObject queryPage(Map<String, String> map) {
		StringBuffer sbuf = new StringBuffer();
		sbuf.append("select a.*,b.YLTMC,c.XM LSZXM,b.BZSM, \n");
		sbuf.append("(select (select XMMC from TB_ZY_YXQ where XMDM = d.QYYXQ) QYYXQMC from TB_JGQY_YLT_YLJG d where YLTID = a.YLTID and JGLX = '3' and JLZT='1') QYYXQMC, \n");
		sbuf.append("(select XMMC from TB_ZY_YLTLX where XMDM = b.YLTLX) YLTLXMC, \n");
		sbuf.append("(select YLJGMC from TB_ZD_YLJGXX where PTJGID = b.ZDYLJGID) ZDYLJGMC \n");
		/*sbuf.append("(select XM from TB_ZD_YLJGRYXX where USERID = a.LSZID) LSZXM \n");*/
		sbuf.append(" from "+this.tb.getTableName()+" a,TB_JGQY_YLT b,TB_ZD_YLJGRYXX c ");
		sbuf.append(" where a.YLTID = b.YLTID and c.USERID = a.LSZID ");
		
		List list = new ArrayList();
		String value = map.get("LSHMC");
		if(!StringUtils.isEmpty(value))
		{
			sbuf.append("and a.LSHMC like ? ");
			list.add("%"+value+"%");
		}
		value = map.get("YLTMC");
		if(!StringUtils.isEmpty(value))
		{
			sbuf.append("and b.YLTMC like ? ");
			list.add("%"+value+"%");
		}
		value = map.get("LSZXM");
		if(!StringUtils.isEmpty(value))
		{
			sbuf.append("and c.XM like ? ");
			list.add("%"+value+"%");
		}
		value = map.get("YLJGID");
		if(!StringUtils.isEmpty(value))
		{
			sbuf.append("and b.YLTID in (select distinct YLTID from TB_JGQY_YLT_YLJG where YLJGID = ? and QYZT in (03,05)) ");
			list.add(value);
		}
		PageQuerySQLBean sb = super.checkAndCreatePageQuerySQLBean(map, sbuf.toString(), "order by a.CLSJ DESC", list.toArray());
		return super.queryPage(sb, ResultHandlerConstant.JSONARRAY);
	}


}
